home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Source / GUI2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  3.7 KB  |  130 lines

  1. #define __USE_SYSBASE
  2. #include <extras/math.h>
  3. #include <proto/exec.h>
  4. #include <proto/intuition.h>
  5. #include <proto/commodities.h>
  6. #include <proto/gadtools.h>
  7. #include <proto/graphics.h>
  8. #include <proto/utility.h>
  9. #include <proto/diskfont.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <math.h>
  15. #include <extras/gui.h>
  16. #include <extras/ext_text.h>
  17. #include <clib/extras_protos.h>
  18.  
  19. float GetGUIStringScale(struct TextAttr *TA, struct GUI_String *Strings);
  20.  
  21. /****** extras.lib/OBSOLETE_GetGUIScale ******************************************
  22. *
  23. *   OBSOLETE
  24. *       Since OS3.5 uses Reaction/ClassAct - this code is obsolete
  25. *
  26. *   NAME
  27. *       GetGUIScale -- Find the appropriate scale for an
  28. *                      interface.
  29. *
  30. *   SYNOPSIS
  31. *       success = GetGUIScale(TAttr, Strings, &XScale, &YScale)
  32. *
  33. *       BOOL GetGUIScale(struct TextAttr *, struct GUI_String *,
  34. *                        float *, float *);
  35. *
  36. *   FUNCTION
  37. *       This function figures out the minimum size an interface
  38. *       should be so that all of the Strings will fit.
  39. *
  40. *   INPUTS
  41. *       TAttr - The TextAttr to be used for the strings.
  42. *       Strings - A NULL terminated array of GUI_String containing
  43. *                 the Strings to used in the interface and the maximum
  44. *                 size each string can be before the interface needs
  45. *                 to be enlarged.
  46. *       XScale - the address of a float to contain the X scale factor.
  47. *       YScale - the address of a float to contain the Y scale factor. 
  48. *
  49. *   RESULT
  50. *       This function returns non-zero on success, and will have the X &
  51. *       YScale values set apropriately.  Returns NULL on failure if the
  52. *       font specified in TAttr can not be opened, and X & YScale will be
  53. *       set to -1.
  54. *
  55. *   NOTES
  56. *       requires diskfont.library to be open.
  57. *
  58. *       The reason this function sets X & YScale to -1 on failure is to
  59. *       also cause CheckWindowSize() and CheckInnerWindowSize to fail.
  60. *       This way you can simply:
  61. *       GetGUIScale(ta,strings,&xscale,&yscale)
  62. *       if(!CheckWindwoWidth(scr,winwidth,winheight,xscale,yscale))
  63. *       { ... revert to topaz.8 ... 
  64. *       }
  65. *
  66. *       The GUI_String specifies the maximum size a string can be before
  67. *       the interface should be scaled horizontally.  For example, if you
  68. *       have a BUTTON_KIND gadget that is 100 pixels wide, then you may
  69. *       want to set the maximum size for the string in that gadget to 90.  
  70. *       (ie.
  71. *            struct GUI_String gs[]=
  72. *            {
  73. *              "Button Text", 90,
  74. *              0,0
  75. *            };
  76. *       )
  77. *
  78. *   SEE ALSO
  79. *       MakeGadgets()
  80. *
  81. ******************************************************************************
  82. *
  83. */
  84.  
  85. BOOL GetGUIScale(struct TextAttr *TA,
  86.                  struct GUI_String *Strings,
  87.                  float *XScale,
  88.                  float *YScale)
  89. {
  90.   float xscale;
  91.   *XScale=*YScale=-1;
  92.   
  93.   xscale=GetGUIStringScale(TA,Strings);  
  94.   if(xscale>0)
  95.   {
  96.     *XScale=xscale;
  97.     *YScale=(float)TA->ta_YSize/8.0;
  98.     *YScale=max(1.0,*YScale);
  99.     return(TRUE);
  100.   }
  101.   return(FALSE);
  102. }
  103.  
  104.  
  105.  
  106. float GetGUIStringScale(struct TextAttr *TA, struct GUI_String *Strings)
  107. {
  108.   struct TextFont *tf;
  109.   ULONG l=0;
  110.   LONG newsize;  
  111.   float increase,maxincrease=1;
  112.   
  113.   if(tf=OpenDiskFont(TA))
  114.   {
  115.     while(Strings[l].String)
  116.     {
  117.       newsize=gui_StrLength(SL_TextFont    ,tf,
  118.                          SL_String      ,Strings[l].String,
  119.                          SL_IgnoreChars ,"_",
  120.                          TAG_DONE);
  121.       increase=(float)newsize/(float)Strings[l].NormalSize;
  122.       maxincrease=max(increase,maxincrease);
  123.       l++;
  124.     }
  125.     CloseFont(tf);
  126.     return(maxincrease);
  127.   }
  128.   return(-1.0);
  129. }
  130.